package com.xyzh05.dao.hibernate;

import java.util.List;

import com.xyzh05.model.Comment;
import com.xyzh05.dao.CommentDao;
import com.xyzh05.dao.hibernate.GenericDaoHibernate;
import org.springframework.stereotype.Repository;

@Repository("commentDao")
public class CommentDaoHibernate extends GenericDaoHibernate<Comment, Long> implements CommentDao {

    public CommentDaoHibernate() {
        super(Comment.class);
    }

	@SuppressWarnings("unchecked")
	public List<Comment> getAllByTime(Long owenId, Long owenType) {
		return this.getHibernateTemplate().find(" from Comment c where c.ownerId = ? and c.ownerType = ? order by c.replyTime desc ", new Object[]{owenId, owenType});	
	}

	@SuppressWarnings("unchecked")
	public List<Comment> getTopNum(Integer vipServiceId, Integer minNum, Integer maxNum) {
		String sql = " from Comment c where c.ownerId = " + vipServiceId + " and c.ownerType in (3, 4, 5, 6) order by c.replyTime desc ";
		return getSession().createQuery(sql).setFirstResult(minNum).setMaxResults(maxNum).list();
	}
}
